package com.jmp.api.service.impl;

import com.jmp.api.service.SunCodeDeleteService;
import com.jmp.api.service.SunCodeService;
import com.jmp.api.service.TemplateCardFacadeService;
import one.stand.mapper.BusinessCardPublicMapper;
import one.stand.mapper.SysWxCodeMapperExt;
import one.stand.model.SysWxCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class SunCodeDeleteServiceImpl implements SunCodeDeleteService {
    @Autowired
    private BusinessCardPublicMapper businessCardPublicMapper;
    @Autowired
    private TemplateCardFacadeService templateCardFacadeService;
    @Autowired
    private SysWxCodeMapperExt sysWxCodeMapperExt;

    @Override
    @Async("asyncServiceExecutor")
    public void delete(Integer companyId) {
        businessCardPublicMapper.updateWxToCode(companyId);//名片二维码

        //企业名片
        SysWxCode sysWxCode = sysWxCodeMapperExt.selectByRefId(SunCodeService.TYPE_COMPANY, String.valueOf(companyId));
        if (Objects.nonNull(sysWxCode)) {
            sysWxCodeMapperExt.deleteByPrimaryKey(sysWxCode.getId());
        }

        //海报
        templateCardFacadeService.removeByCompanyId(companyId);
    }
}
